package com.fr71.project.dm.controller;

import com.fr71.framework.aspectj.lang.annotation.Log;
import com.fr71.framework.aspectj.lang.enums.BusinessType;
import com.fr71.framework.web.controller.BaseController;
import com.fr71.framework.web.domain.AjaxResult;
import com.fr71.framework.web.page.TableDataInfo;
import com.fr71.common.utils.poi.ExcelUtil;
import com.fr71.project.dm.domain.PdChangeLog;
import com.fr71.project.dm.service.IPdChangeLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 开发者：https://github.com/devzwy
 * 创建时间：2023-07-07
 * 类描述：换绑记录Controller
 */
@RestController
@RequestMapping("/dm/change_log")
public class PdChangeLogController extends BaseController {
    
    @Autowired
    private IPdChangeLogService pdChangeLogService;

    /**
     * 查询换绑记录列表
     */
    @PreAuthorize("@ss.hasPermi('dm:change_log:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdChangeLog pdChangeLog) {
        startPage();
        List<PdChangeLog> list = pdChangeLogService.selectPdChangeLogList(pdChangeLog);
        return getDataTable(list);
    }

    /**
     * 导出换绑记录列表
     */
    @PreAuthorize("@ss.hasPermi('dm:change_log:export')")
    @Log(title = "换绑记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdChangeLog pdChangeLog) {
        List<PdChangeLog> list = pdChangeLogService.selectPdChangeLogList(pdChangeLog);
        ExcelUtil<PdChangeLog> util = new ExcelUtil<PdChangeLog>(PdChangeLog.class);
        util.exportExcel(response, list, "换绑记录数据");
    }

    /**
     * 获取换绑记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('dm:change_log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pdChangeLogService.selectPdChangeLogById(id));
    }

    /**
     * 新增换绑记录
     */
    @PreAuthorize("@ss.hasPermi('dm:change_log:add')")
    @Log(title = "换绑记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdChangeLog pdChangeLog) {
        return toAjax(pdChangeLogService.insertPdChangeLog(pdChangeLog));
    }

    /**
     * 修改换绑记录
     */
    @PreAuthorize("@ss.hasPermi('dm:change_log:edit')")
    @Log(title = "换绑记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdChangeLog pdChangeLog) {
        return toAjax(pdChangeLogService.updatePdChangeLog(pdChangeLog));
    }

    /**
     * 删除换绑记录
     */
    @PreAuthorize("@ss.hasPermi('dm:change_log:remove')")
    @Log(title = "换绑记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pdChangeLogService.deletePdChangeLogByIds(ids));
    }
}